package com.globallogic.training.javase.university.schedule;

import org.apache.commons.lang3.StringUtils;

/**
 * Location in the university campus.
 * 
 * @author Artem.Zeltinsh
 */
public class Auditorium {

	private int buildingId;

	private int roomId;

	public Auditorium(String id) {
		this.buildingId = Integer
				.parseInt(StringUtils.substringBefore(id, "-"));
		this.roomId = Integer.parseInt(StringUtils.substringAfter(id, "-"));
	}

	public Auditorium(int buildingId, int roomId) {
		this.buildingId = buildingId;
		this.roomId = roomId;
	}

	public int getBuildingId() {
		return buildingId;
	}

	public int getRoomId() {
		return roomId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = result * prime + buildingId;
		result = result * prime + roomId;

		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}

		if (!getClass().equals(obj.getClass())) {
			return false;
		}

		Auditorium other = (Auditorium) obj;
		if (buildingId == other.buildingId && roomId == other.roomId) {
			return true;
		}

		return false;
	}

	@Override
	public String toString() {
		return buildingId + "-" + roomId;
	}
}
